package com.xxxx.server.controller;


import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IAdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 */
@RestController
@RequestMapping("/system")
public class AdminController {
    @Autowired
    private IAdminService iAdminService;

    @ApiOperation(value="获取管理员")
    @GetMapping("/admin")
    public List<Admin> getAllAdmins(String keywords){
        List<Admin> list = iAdminService.getAllAdmins(keywords);
        return list;
    }

    @ApiOperation(value="通过aid获取该管理员的角色列表")
    @GetMapping("/admin/roles")
    public List<Role> getAdminRoles(){
        List<Role> list = iAdminService.getAllRoles();
        return list;
    }

    @ApiOperation(value="通过rid和aid更新该管理员的角色列表")
    @PutMapping("/admin/role")
    public RespBean updateAdminRoles(Integer adminId, Integer[] rids){
        return iAdminService.updateAdminRoles(adminId,rids);
    }

   /* @ApiOperation(value="通过rid删除该管理员的角色列表")
    @PutMapping("/admin/role/{id}")
    public RespBean updateAdminRoles(@PathVariable("id")Integer adminId){
        return iAdminService.updateAdminRoles(adminId);
    }*/

    @ApiOperation("删除管理员")
    @DeleteMapping("/admin/{id}")
    public RespBean deleteAdmin(@PathVariable("id") Integer id){
        return iAdminService.deleteAdmin(id);
    }

    @ApiOperation("管理员启用与否")
    @PutMapping("/admin")
    public RespBean enabledAdmin(@RequestBody Map<String,Object> admin){
        return iAdminService.enabledAdmin(admin);
    }


}
